#include <d3dx9.h>
#include "Texture2DDX9.h"

mBool CTexture2DDX9::CreateFromFile( mString a_sFileName )
{
    mBool bRes = (D3DXCreateTextureFromFileA( g_D3DDevice.pD3D9Device, a_sFileName.c_str(), &m_pTexture ) == D3D_OK);

    if (bRes)
    {
        m_pTexture->GetSurfaceLevel(0, &m_pTextureSurface);
    }

    return bRes;
}

mBool CTexture2DDX9::Create(mUInt a_uWidth, mUInt a_uHeight, TImageFormat a_ImageFmt )
{
    mBool bRes = (D3DXCreateTexture(g_D3DDevice.pD3D9Device, 
        a_uWidth, a_uHeight, 
        1, 
        D3DUSAGE_RENDERTARGET, 
        DX9ImageFmt(a_ImageFmt), 
        D3DPOOL_DEFAULT, 
        &m_pTexture) == D3D_OK);
    m_uHeight  = a_uHeight;
    m_uWidth   = a_uWidth;
    m_ImageFmt = a_ImageFmt;
    return bRes;
}

CTexture2DDX9::CTexture2DDX9( )
{
    m_pTexture = NULL;
}

CTexture2DDX9::~CTexture2DDX9( )
{
    SAFE_RELEASE(m_pTexture);
    SAFE_RELEASE(m_pTextureSurface);
}

IDirect3DTexture9 *CTexture2DDX9::Texture( )
{
    return m_pTexture;
}